﻿using System;

namespace DBCore.DB
{
    [Serializable()]
    public class DbParam
    {
        public string Name;
        public object Value;
        public DbDataType DataType = DbDataType.String;
        public DbParam() { }
        public DbParam(string name, object value)
        {
            this.Name = name;
            this.Value = value;
            DataType = GetDbDataType(value.GetType());
        }
        public DbParam(string name, object value, DbDataType type)
        {
            this.Name = name;
            this.Value = value;
            this.DataType = type;
        }

        public static DbDataType GetDbDataType(Type t)
        {
            var dtype = DbDataType.String;
            switch (t.ToString().ToLower())
            {
                case "int64":
                    dtype = DbDataType.BigInt;
                    break;
                case "string":
                    dtype = DbDataType.String;
                    break;
                case "datetime":
                    dtype = DbDataType.DateTime;
                    break;
                case "char":
                    dtype = DbDataType.Char;
                    break;
                default:
                    dtype = DbDataType.String;
                    break;
            }
            return dtype;
        }
    }
}
